package com.emm.yixun.openapi.hander;

import net.sf.ehcache.CacheManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.common.app.CheckCustomerPhoneReqDto;
import com.emm.yixun.common.app.CheckCustomerPhoneResDto;
import com.emm.yixun.common.exception.XFUNExceptionCode;
import com.emm.yixun.customer.service.app.CustomerServiceAppFacade;
import com.emm.yixun.openapi.dto.base.BaseRequestDTO;
import com.emm.yixun.openapi.dto.base.BaseResponseDTO;
import com.emm.yixun.openapi.hander.base.CommonAbstractHander;
import com.emm.yixun.openapi.vo.CheckCustomerPhoneReqVo;

/**
 * 新增客户,手机号重复验证
 * @author Administrator
 *
 */
@Service("checkCustomerPhoneHander")
public class CheckCustomerPhoneHander extends CommonAbstractHander{
	
	@Autowired
	private CustomerServiceAppFacade customerServiceAppFacade;
	@Autowired
	private CacheManager cacheManager;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		CheckCustomerPhoneReqVo req = (CheckCustomerPhoneReqVo) reqDto;
		CheckCustomerPhoneReqDto reqDto1 = req.getParams();
		BaseResponseDTO<CheckCustomerPhoneResDto> res = new BaseResponseDTO<CheckCustomerPhoneResDto>();
		CheckCustomerPhoneResDto resDto = new CheckCustomerPhoneResDto();
		try{
			/*
			Cache  cache = cacheManager.getCache("activeSessionsCache");
			//获取userCode缓存对应value值
			String u_userCode = reqDto1.getMerchantId() + reqDto1.getUserId() + "userCode";//获取userCode缓存key
			Element element_userCode = cache.get(u_userCode );
			String ele_userCode = (String) element_userCode .getValue();
			//获取userCode缓存key
			String u_projectId = reqDto1.getMerchantId() + reqDto1.getUserId() + "projectId";
			Element element_projectId = cache.get(u_projectId );
			String ele_projectId= (String) element_projectId .getValue();//获取userCode缓存对应value值
			
			reqDto1.setUserCode(ele_userCode);
			reqDto1.setProjectId(Long.parseLong(ele_projectId));
			*/
			resDto = customerServiceAppFacade.checkCustomerPhone(reqDto1);
		} catch (Exception e) {
			if("customer".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("新增客户操作失败");
				resDto.setResult("0");
			}else if("houseType".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("关注户型操作失败");
				resDto.setResult("0");
			}else if("premises".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("意向组团操作失败");
				resDto.setResult("0");
			}else if("room".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("意向房号操作失败");
				resDto.setResult("0");
			}else if("family".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("家庭成员操作失败");
				resDto.setResult("0");
			}else{
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg(XFUNExceptionCode.UNKNOW_EXCEPTON.getDesout());
				resDto.setResult("0");
			}
		}
		res.setResData(resDto);
		return res;
	}
	
}
